package me.yricky.cov_spectrum.model.utils

import java.time.LocalDate
import java.time.chrono.IsoChronology
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatterBuilder
import java.time.format.ResolverStyle
import java.time.temporal.ChronoField

val formatter = DateTimeFormatterBuilder()
    .parseCaseInsensitive()
    .appendValue(ChronoField.YEAR, 4)
    .appendLiteral('-')
    .appendValue(ChronoField.MONTH_OF_YEAR, 2)
    .appendLiteral('-')
    .appendValue(ChronoField.DAY_OF_MONTH, 2)
    .optionalStart()
    .parseLenient()
    .parseStrict()
    .toFormatter()

fun date() = LocalDate.now()

fun datePrev(prevDay:Long) = LocalDate.ofEpochDay(
    LocalDate.now().toEpochDay() - prevDay
)

val LocalDate.str get() = format(formatter)